import request from '@/utils/request'
import axios from "axios";

const api_name = `/api/oss/file`

export default {
  getPolicy() {
    return request({
      url: `${api_name}/getPolicy`,
      method: `get`
    })
  },
  uploadImgOss(data, file) {
    let {ossAccessKeyId, policy, signature, host, callback} = data;
    let formData = new FormData();
    formData.append("key", `${new Date().getTime()}_${file.name}`);
    formData.append("success_action_status", 200);  // 让服务端返回200，不设置则默认返回204。
    formData.append("OssAccessKeyId", ossAccessKeyId);
    formData.append("policy", policy);
    formData.append("signature", signature);
    formData.append("callback", callback);
    formData.append("file", file); // 必须放在最后
    return axios({
      method: "post",
      url: host,
      data: formData
    });
  }
}
